package com.svms.service.mapper;

import org.apache.commons.lang.StringUtils;

import com.svms.model.SvmsVehicleSpare;
import com.svms.service.factory.SvmsServiceFactory;
import com.svms.service.vo.SpareCodesVO;
import com.svms.service.vo.VehicleSpareVO;
import com.svms.service.vo.VehicleVO;

public class VehicleSpareMapper {

	public static SvmsVehicleSpare serviceToDml(VehicleSpareVO vehcileSpareVO) {

		SvmsVehicleSpare svmsVehicleSpare = new SvmsVehicleSpare();

		svmsVehicleSpare.setVehicleSpareId(Long.valueOf(vehcileSpareVO
				.getVehicleSpareId()));
		svmsVehicleSpare.setSpareId(Long.valueOf(vehcileSpareVO.getSpareId()));
		svmsVehicleSpare.setVehicleId(vehcileSpareVO.getVehicleVO()
				.getVehicleId());
		System.out.println("@@@ " + vehcileSpareVO.getInvoiceNumber());
		svmsVehicleSpare.setInvoiceNumber(Long.valueOf(vehcileSpareVO
				.getInvoiceNumber()));
		svmsVehicleSpare.setInstallationDate(vehcileSpareVO
				.getInstallationDate());
		svmsVehicleSpare.setDistanceTraveled(Integer.valueOf(StringUtils
				.isBlank(vehcileSpareVO.getDistanceTraveled()) ? "0"
				: vehcileSpareVO.getDistanceTraveled()));
		svmsVehicleSpare.setDaysTraveled(Integer.valueOf(StringUtils
				.isBlank(vehcileSpareVO.getDaysTraveled()) ? "0"
				: vehcileSpareVO.getDaysTraveled()));

		return svmsVehicleSpare;

	}

	public static VehicleSpareVO dmlToService(SvmsVehicleSpare svmsVehicleSpare) {
		VehicleSpareVO vehicleSpareVO = new VehicleSpareVO();

		vehicleSpareVO.setVehicleSpareId(String.valueOf(svmsVehicleSpare
				.getVehicleSpareId()));

		VehicleVO vehicle = new VehicleVO();
		vehicle.setVehicleId(svmsVehicleSpare.getVehicleId());
		vehicleSpareVO.setVehicleVO(SvmsServiceFactory.getInstance()
				.getVehicle().getVehicle(vehicle));

		SpareCodesVO codesVO = new SpareCodesVO();
		codesVO.setSpareId(String.valueOf(svmsVehicleSpare.getSpareId()));
		vehicleSpareVO.setSpareCodes(SvmsServiceFactory.getInstance()
				.getSpareDetails().getSpareDetails(codesVO));

		vehicleSpareVO.setInvoiceNumber(String.valueOf(svmsVehicleSpare
				.getInvoiceNumber()));
		vehicleSpareVO.setInstallationDate(svmsVehicleSpare
				.getInstallationDate());
		vehicleSpareVO.setDaysTraveled(String.valueOf(svmsVehicleSpare
				.getDaysTraveled()));
		vehicleSpareVO.setDistanceTraveled(String.valueOf(svmsVehicleSpare
				.getDistanceTraveled()));

		return vehicleSpareVO;
	}

}
